---
title: "Results of Pilot Survey"
author: ""
date: "2025-05-23"
output:
  pdf_document: default
  html_document: default
---

```{r, echo = T, results = 'hide',  error=FALSE, warning=FALSE, message=FALSE}
library(tidyverse)
library(readxl)
library(ggpubr)
```

```{r, echo = T, results = 'hide',  error=FALSE, warning=FALSE, message=FALSE}
## First round of pilot for DV variability questions (n=125)
mil_pilot <- read_xlsx("pilot_data.xlsx")

## Second round of pilot for operationalization and seriousness questions (n=52)
mil_pilot_2 <- read_xlsx("measures_pilot_actual.xlsx")
```

```{r}
## Data Preparation
# First round
scenario <- mil_pilot %>% select(riskownlife, riskotherlife:obeyorder) 
mil_pilot$main_response <- rowSums(scenario, na.rm = T)

scenario <- mil_pilot %>% select(riskownlife2, risktheirlife2:obeyorder2) 

mil_pilot$selected2  <- as.vector(ifelse(is.na(scenario[,1]) ==F , 1, 
       ifelse(is.na(scenario[,2]) == F , 2, 
              ifelse(is.na(scenario[,3]) == F, 3,
                     ifelse(is.na(scenario[,4]) == F , 4, 
                            ifelse(is.na(scenario[,5]) == F , 5, 
                                   ifelse(is.na(scenario[,6]) == F, 6,NA)))))))

mil_pilot$main_response2 <- rowSums(scenario, na.rm = T)

mil_pilot1 <- mil_pilot %>% select(dims_1:dims_6,objective:tie,selected,
                                   main_response)
mil_pilot2 <- mil_pilot %>% select(dims2_1:dims2_6,objective2:tie2,selected2,
                                   main_response2)

colnames(mil_pilot2) <- colnames(mil_pilot1)
mil_pilot1$order <- 1
mil_pilot2$order <- 2

dat <- mil_pilot1 %>% bind_rows(mil_pilot2)


dat = mutate(dat, selected = case_when(selected == "1" ~ "Risk Life",
                                       selected == "2" ~ "Risk Subordin",
                                       selected == "3" ~ "Discretion",
                                       selected == "4" ~ 
                                         "Coordination",
                                       selected == "5" ~ "Unit Cohesion",
                                       selected == "6" ~ "Compliance") )


# Second round
mil_pilot_2 <- rename(mil_pilot_2, "Taiwan Invasion" = "seriousness_1")
mil_pilot_2 <- rename(mil_pilot_2, "Liberal Party" = "seriousness_2")
mil_pilot_2 <- rename(mil_pilot_2, "DPRK Collapse" = "seriousness_3")

dat_2 <- mil_pilot_2 %>% select(measure_risklife_1:measure_obey_6)  %>% 
  pivot_longer(measure_risklife_1:measure_obey_6)

dat_2$name <- gsub('measure_', '', dat_2$name)
dat_2 <- dat_2 %>% separate_wider_delim(name, delim = "_", names = c("scenario", 
                                                                 "dimension"))


dat_2 = mutate(dat_2, dimension = case_when(dimension  == "1" ~ 
                                              "Order Compliance",
                                            dimension  == "2" ~ "Discretion",
                                            dimension  == "3" ~ "Risk Life",
                                            dimension  == "4" ~ 
                                              "Risk Subordinates",
                                            dimension  == "5" ~ 
                                              "Interunit Coordination",
                                            dimension  == "6" ~ 
                                              "Unit cohesion") )

dat_2 = mutate(dat_2, scenario = case_when(scenario  == "obey" ~ 
                                             "Compliance",
                                            scenario  == "discretion" ~ 
                                             "Discretion",
                                            scenario  == "risklife" ~ 
                                             "Risk Life",
                                            scenario  == "risksubordin" ~ 
                                              "Risk Subordin",
                                            scenario  == "coordinate" ~ 
                                              "Coordination",
                                            scenario  == "unitco" ~ 
                                              "Unit Cohesion") )
```

```{r, warning = FALSE, fig.height = 10}
## Variability of the Dependent Variable
fig1 <- ggplot(dat, mapping = aes(x = main_response)) +
  geom_bar(mapping = aes(fill = main_response)) + theme_bw() +
  facet_grid(cols = vars(selected)) + xlab("Baseline Response to DV Tasks
(-2 = Highly Reluctant to ~ 2 = Highly Willing to)") +
  ggtitle("Response to DV tasks")


fig2 <- ggplot(dat, mapping = aes(x = objective)) +
  geom_bar(mapping = aes(fill = objective)) + theme_bw() +
  facet_grid(cols = vars(selected)) + xlab("Varying National Objectives") +
  ggtitle("How subjects would alter their responses given each contextual variation
(1 = Not at all ~ 5 = A great deal)")


fig3 <- ggplot(dat, mapping = aes(x = enemy)) +
  geom_bar(mapping = aes(fill = enemy)) + theme_bw() +
  facet_grid(cols = vars(selected)) + xlab("Varying Who the Enemy Is") +
  ggtitle("")


fig4 <- ggplot(dat, mapping = aes(x = risk)) +
  geom_bar(mapping = aes(fill = risk)) + theme_bw() +
  facet_grid(cols = vars(selected)) + xlab("Varying Degrees of Personal Risk") +
  ggtitle("")

fig5 <- ggplot(dat, mapping = aes(x = tie)) +
  geom_bar(mapping = aes(fill = tie)) + theme_bw() +
  facet_grid(cols = vars(selected)) + xlab("Varying Degrees of Within-Unit Tie") +
  ggtitle("")


ggarrange(fig1, fig2, fig3, fig4, fig5,
                    ncol = 1)
```

```{r, warning = FALSE}
## Seriousness of Scenarios to Be Used in Main Experiments
mil_pilot_2 %>% select("Taiwan Invasion":"DPRK Collapse") %>%
  pivot_longer("Taiwan Invasion":"DPRK Collapse") %>%
  ggplot(mapping = aes(x = value)) +
  geom_bar(mapping = aes(fill = value)) +
  facet_grid(rows = vars(name))+ theme_bw() +
  xlab("Response to: \"How seriously or not seriously would you take a 
       training simulation exercise that includes the following contextual details?\"") + 
  ylab("Count of Participants") +
  scale_x_continuous(
    breaks = c(-2,-1,0,1,2),
    labels = c("Not at all", "A little", "Moderate", "A lot",
                  "A great deal"))
```

```{r, warning = FALSE, fig.width = 8}
## Validity of the Survey Questions for Six Military Cohesion Dimensions
dat_2$scenario2 = factor(dat_2$scenario, levels=c('Unit Cohesion',
                                                  'Risk Subordin','Risk Life',
                                                  'Compliance', 'Coordination',
                                                  'Discretion'))

dat_2 %>% ggplot(aes(x = value, y = dimension)) +
  geom_boxplot(outlier.shape = NA, width = 0.5) + 
  geom_point(position = position_jitter(w=0.22, h=.22),alpha=.2, size=.9) +
  facet_grid(cols = vars(scenario2)) + theme_bw() +
  xlab("Question for Measuring Each Dimension
(-2 = Highly irrelevant ~ 2 = Highly relevant)") +
  ylab("Dimensions of Military Cohesion")
```